package com.business.sys.controller;


import com.alibaba.fastjson.JSONObject;
import com.business.common.dto.R;
import com.business.redis.constant.RedisKeyConstant;
import com.business.redis.utils.RedisUtil;
import com.business.sys.entity.Config;
import com.business.sys.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统配置类: 后端controller类
 *
 * @author chenjiehong
 * @date 2019-04-28 15:03:18
 * @since 1.0
 */
@RestController
@RequestMapping(value = "/com/business/common/config")
public class ConfigController {


    @Autowired
    private ConfigService sysConfigServiceImpl;


    /**
     * 查询系统配置类
     *
     * @param code
     * @date 2019-04-28 15:03:18
     */
    @GetMapping("/queryByCode")
    @ResponseBody
    public R query(@RequestParam String code) {
        String key = String.format(RedisKeyConstant.CONFIG_QUERY_BY_CODE, code);
        if (RedisUtil.hasKey(key)) {
            return R.success(RedisUtil.getValue(key));
        } else {
            Config r = sysConfigServiceImpl.query(code);
            //永久缓存
            RedisUtil.setValue(key, r);
            return R.success(r);
        }

    }

}